import { ref } from 'vue'
import PageTable from '@/components/PageTable/PageTable.vue'
import { IForm } from '@/base-ui/Form/types'
export function usePageSearch(config?: IForm) {
  const pageTableRef = ref<InstanceType<typeof PageTable>>()
  const resetBtnClick = () => {
    pageTableRef.value?.getPageData()
  }
  const searchBtnClick = (queryInfo: any) => {
    const obj: any = {}
    if (config) {
      // debugger
      for (const item of config.formItems) {
        if (item.options) {
          for (const i of item.options) {
            if (queryInfo[item.field] === i.title) {
              console.log(queryInfo[item.field], i.title)
              obj[item.field] = i.value
            }
          }
        }
      }
    }
    pageTableRef.value?.getPageData({ ...queryInfo, ...obj })
  }
  return [pageTableRef, resetBtnClick, searchBtnClick]
}
